from selenium.webdriver.common.by import By
from base.page_base import BasePage


class AccountPage(BasePage):
    """开通托管账户"""

    def __init__(self, driver):
        """
        初始化方法：设置实例属性
        :param driver: 浏览器驱动
        """
        super().__init__(driver)
        # 获取元素
        self.act = (By.XPATH, '//*[@id="step3"]/div/div/div/div/a')
        self.name = (By.XPATH, '//*[@id="safeName"]/div[2]/input')
        self.card = (By.XPATH, '//*[@id="safeName"]/div[3]/input')
        self.submit = (By.XPATH, '//*[@id="safeName"]/div[5]/div/input')
        self.act1 = (By.XPATH, '//*[@id="successForm"]/input')
        self.handle = (By.XPATH,'/html/body')

    def open_account(self, name, card):
        """
        开通托管账户
        :param name: 姓名
        :param card: 身份证号
        :return: 无
        """
        # 注册之后：开通托管账户
        self.base_click(self.act)
        # 输入姓名
        self.base_input(self.name, name)
        # 输入身份证
        self.base_input(self.card, card)
        # 点击提交
        self.base_click(self.submit)

    def act_account(self):
        # 点击立即开通
        self.base_click(self.act1)

    def get_result_success(self):
        """
        获取开通托管账户成功结果
        :return: 获取结果
        """
        # 获取结果
        result = self.get_handles(self.handle).text
        return result
